<?php
require('../config.php');

		$user_id=$_REQUEST['user_id'];
		$start=0;
		$num=10;
		if(isset($_REQUEST['start'])) $start=$_REQUEST['start'];
		if(isset($_REQUEST['num'])) $num=$_REQUEST['num'];
		$sql="select m.id,m.shopid,m.shopname,m.shopqishu,sum(m.gonumber) as gonumber,s.zongrenshu,s.canyurenshu,s.shenyurenshu,s.sid,s.qishu from `".$oto."_member_go_record` as m,`".$oto."_shoplist` as s where `uid`='{$user_id}' and m.shopid=s.id group by m.shopid order by id DESC limit $start,$num";
		$result=$db->query($sql);
		while($row=$result->fetch_assoc()){
			$member_go_record[]=$row;//将取得的所有数据赋值给person_info数组
		}
		if(isset($member_go_record))
		{
			for($i=0;$i<count($member_go_record);$i++)
			{
				$id=$member_go_record[$i]['shopid'];
				$sql="select s.thumb,s.q_user_code,s.q_uid,u.userName,s.money from `".$oto."_shoplist` as s,`".$oto."_users` as u where s.id='{$id}' and s.q_uid=u.userId";
				$result=$db->query($sql);
				while($row=$result->fetch_assoc()){
					$shoplist[$i]=$row;//将取得的所有数据赋值给person_info数组
				}
				$sql="select s.thumb,s.q_user_code,s.q_uid,u.userName,s.money from `".$oto."_shoplist` as s,`".$oto."_users` as u where s.id='{$id}'";
				$result=$db->query($sql);
				while($row=$result->fetch_assoc()){
					$shoplist2[$i]=$row;//将取得的所有数据赋值给person_info数组
				}
				if(isset($shoplist2[$i]))
				{
					$member_go_record[$i]['thumb']=$shoplist2[$i]['thumb'];
				}
				else
				{
					$member_go_record[$i]['thumb']="";
				}
				if(isset($shoplist[$i]))
				{
					$member_go_record[$i]['q_user_code']=$shoplist[$i]['q_user_code'];
					$member_go_record[$i]['q_uid']=$shoplist[$i]['q_uid'];
					$member_go_record[$i]['userName']=$shoplist[$i]['userName'];
					$member_go_record[$i]['money']=$shoplist[$i]['money'];
				} 
				else
				{
					$member_go_record[$i]['q_user_code']="";
					$member_go_record[$i]['q_uid']="";
					$member_go_record[$i]['userName']="";
					$member_go_record[$i]['money']="";
				} 
				//获取期数
				$sid=$member_go_record[$i]['sid'];
				$sql="select s.qishu from `".$oto."_shoplist` as s where sid='{$sid}' order by qishu desc limit 1";
				$result=$db->query($sql);
				while($row=$result->fetch_assoc()){
					$qishu_info=$row;
				}
				if(isset($qishu_info)) $member_go_record[$i]['max_qishu']=$qishu_info['qishu'];
				else $member_go_record[$i]['max_qishu']="";
			}
			echo json_encode($member_go_record);
		}
		else echo '[]';

?>